package ert;

import robocode.control.BattlefieldSpecification;
import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Tests if RiceMusubi moves on the opposite way when it hits a wall.
 * @author Emerson Tabucol
 * Adapted code from TestDaCruzerMovement.java
 *
 */
public class TestRiceMusubiMoveOpposite extends RobotTestBed {
  /** True if the robot visited any corner during the test case. */
  boolean turnedOppositeWay = false;
  /** True if the robot visited any corner during the test case. */
  boolean hitWall = false;
  
  /**
   * Specifies that SittingDuck and DaCruzer are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,ert.RiceMusubi";
  }
  
  /**
   * This test runs for 10 round.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 10;
  }
  
  /**
   * After each turn, check to see if we're at a corner and then in the center.
   * @param event Info about the current state of the battle.
   */
  @Override 
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    BattlefieldSpecification b = new BattlefieldSpecification();
    double xBattleField = b.getWidth();
    double yBattleField = b.getHeight();
    double xPos = robot.getX();
    double yPos = robot.getY();
    double bodyHeading = robot.getBodyHeading();
    
    if ( (xPos <= 40) || (xPos >= (xBattleField - 40)) || (yPos <= 40) 
        || (yPos >= (yBattleField - 40)) ) {
   
      hitWall = true;
    }
    
    
 // check if robot turned
    if (bodyHeading >= 89 || bodyHeading <= 91) {
      //System.out.print("Turned1");
      turnedOppositeWay = true;
    }
   
    
  }
  
  /**
   * After the battle, check to see that the robot went into the center. 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check if robot hits a wall", hitWall);
    assertTrue("Check if robots turned away from the wall", turnedOppositeWay);
    
  }

}
